<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand" />
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
<title>任务提交情况</title>

<%@ include file="/common/commonLib.jsp"%>
<link rel="stylesheet" type="text/css" href="<c:url value='/css/common-main.css'/>"/>
<link rel="stylesheet" type="text/css" href="<c:url value='/css/courseTaskIndex.css'/>" />

<script src="<c:url value='/js/courseTaskSubmit.js'/>" type="text/javascript" charset="utf-8"></script>
</head>
<body>
	<div class="container-fluid main">
		<!-- 任务提交情况 -->
		<div class="row">
			<div class="col-md-12">
				<%@include file="/common/header.jsp"%>
			</div>
			<div class="col-md-12">
				<%@include file="common/courseHeader.jsp"%>
			</div>
			<div class="col-md-12">
				<div class="row">
					<div class="col-md-3">
						<%@include file="common/courseLeft.jsp"%>
					</div>
					<div class="col-md-9">
						<div class="row">
							<div class="col-md-12">
								<%@include file="common/courseNavbar.jsp"%>
							</div>
							<div class="col-md-12">
								<div class="tab-nav">
									<a id="task-submit-href1" class="front-nav">任务首页
									</a>&nbsp;>&nbsp;<a id="task-submit-href2" class="front-nav">任务详情
									</a>&nbsp;>&nbsp;<a id="task-submit-href3" class="front-nav">任务分配情况
									</a>&nbsp;>&nbsp;<span  class="back-nav">任务提交记录</span>
								</div>
							</div>
							<div class="col-md-12" style="margin-top:1rem;margin-left:4rem;">
								<div class="row">
									<div class="col-md-12">
										任务名：<a id="task-name" style="color:red;"></a>
									</div>
									<div class="col-md-12">
										所发布的课堂信息：<a id="lesson-date" style="color:blue;"></a>
										上课地点：<a id="lesson-location" style="color:green;"></a>
									</div>
								</div>								
							</div>
							<shiro:hasRole name="teacher">
							<div class="col-md-12" style="margin-top:2rem;">
								<div class="row">
									<div class="col-md-1 col-sm-0"></div>									
									<div class="col-md-2 col-sm-3">
										<div class="infor infor-n function-btn" title="批量下载是拉取提交内容中的附件信息。如果提交附件为空，提交的文件可能在富文本框中，请额外下载或者将图片补交至附件">
											<div class="infor-d infor-nd"></div>提交附件为空</div>
									</div>
									<div class="col-md-3 col-sm-3">
										<a type="button" id="review-all" class="btn btn-success function-btn" title="快速登记成绩">快速登记成绩</a>
									</div>
									<div class="col-md-3 col-sm-3">
										<input type="button" id="download-all" class="btn btn-primary function-btn" value="批量下载附件">
									</div>
									<div class="col-md-3 col-sm-3">
										<input type="button" id="score-task-now" class="btn btn-warning function-btn" value="更改提交状态">
									</div>
								</div>								
							</div>
							</shiro:hasRole>
							<div class="col-md-12" style="margin-top:1rem;">									
								<div class="row">
									<div class="col-md-1"></div>
									<div class="col-md-10">
										<table class="table table-hover">
											<thead>
												<tr>
													<th>学号</th>
													<th>提交者</th>
													<th>提交时间</th>
													<th>待批阅者</th>
													<th>共享状态</th>
													<th>
														<select class="form-control" id="submitStatus" onchange="searchSubmit()" >
															<option value="ALL">全部</option>
															<option value="UNCOMMITTED">未提交</option>
															<option value="COMMITTED">已提交</option>
															<option value="HAVEREAD">已批阅</option>
														</select>
													</th>
												</tr>
											</thead>
											<tbody id="submitList">
												
											</tbody>
										</table>
									</div>
									<div class="col-md-1"></div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		
	</div>
	<%@include file="/common/footer.jsp"%>
	<!-- 更改提交状态确认页面 -->
	<div class="modal fade" id="ensure-to-change-submit-status-layer">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header" style="text-align:center;">
					<h2 class="modal-title" style="display:inline;float:left;">是否更改未提交学生的提交状态？</h2>
					<button type="button" class="close" data-dismiss="modal" style="display:inline;float:right;">&times;</button>
				</div>
				<div class="modal-body">
					<div class="row">
						<div class="col-xs-12">
							<div class="build-excel-layer-title">
								<span style="white-space:pre;">  </span><span class="detail-title"><b style="color:red;">提示：</b></span>  
							</div>
						</div>
						<div class="col-xs-12">
							<div class="form-group">
								<div class="row">
									<div class="col-xs-2"></div>
									<div class="col-xs-8">
										<label for="">更改学生任务提交状态功能是为了在以下情况下方便给学生评分;<br>&nbsp;&nbsp;1.任务提交形式变化;<br>&nbsp;&nbsp;2.学生没有在规定时限内提交等。<br><br>(点击"更改提交状态"按钮<b style="color:green;">不会影响</b><i style="color:#1266d2;">已提交学生的信息</i>,仅仅是对提交状态为《未提交》的学生任务进行状态修改)</label>
									</div>
									<div class="col-xs-2"></div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="modal-footer" style="text-align:center;">
					<button type="button" id="cancelChange" class="btn btn-primary" style="margin-right: 2rem;">取消</button>
					<button type="button" id="confirmChange" class="btn btn-primary" style="margin-left: 2rem;">确认</button>
				</div>
			</div>
		</div>
	</div>
	<!-- 批量下载文件确认页面 -->
	<div class="modal fade" id="ensure-to-download-all-layer">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header" style="text-align:center;">
					<h2 class="modal-title" style="display:inline;float:left;">请确认是否下载？</h2>
					<button type="button" class="close" data-dismiss="modal" style="display:inline;float:right;">&times;</button>
				</div>
				<div class="modal-body">
					<div class="row">
						<div class="col-xs-12">
							<div class="build-excel-layer-title">
								<span style="white-space:pre;">  </span><span class="detail-title"><b style="color:red;">提示：</b></span>  
							</div>
						</div>
						<div class="col-xs-12">
							<div class="form-group">
								<div class="row">
									<div class="col-xs-2"></div>
									<div class="col-xs-8">
										<label for="">本次下载是将<b style="color:green;">当前页面下(授课大班)所有学生</b>以<i style="color:red;">《附件形式提交的文件》</i>打包下载.<br><br>若有学生不是以附件的形式提交的文件(如,提交在任务详情文本框中,显示为<i style="color:#eab0b0;">红色</i>),请您下载到本地后,再点击补交附件按钮提交到附件,并点击确定,将文件添加到附件中,再执行批量下载.</label>
									</div>
									<div class="col-xs-2"></div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="modal-footer" style="text-align:center;">
					<button type="button" id="cancel" class="btn btn-primary" style="margin-right: 2rem;">取消</button>
					<a id="download-url" href="" target="_blank" style="color:#fff;"><button type="button" id="confirm" class="btn btn-primary" style="margin-left: 2rem;">确认</button></a>
				</div>
			</div>
		</div>
	</div>
</body>
<script>
var data=${data};

$(document).ready(function() {
	if (data.status != "success") {
		alert(data.message);
		return;
	}
	$("#task").css("color","#00b43c");
	changeUrl(data.data.courseId);
	fetchCourse(data.data.courseId);
	/* information */
	$("#task-name").html(data.data.task.title);
	$("#lesson-date").html(data.data.lesson.beginDate+" to "+data.data.lesson.endDate);
	$("#lesson-location").html(data.data.lesson.location);
	/* btn init */
	$("#confirmChange").click(scoreNow);
	$("#download-all").click(downloadAll);
	$("#review-all").attr("href",CONTEXT_PATH + "taskSubmitResult/loadReview?assignId=" + data.data.assignId);
	
	initList(data.data);
	
	$("#task-submit-href1").attr("href",CONTEXT_PATH + "task/list?courseId=" + data.data.courseId);
 	$("#task-submit-href2").attr("href",CONTEXT_PATH + "task/detail?id=" + data.data.taskId );
 	$("#task-submit-href3").attr("href",CONTEXT_PATH + "taskAssignView/taskMainList?taskId=" + data.data.taskId);	
});
var scoreNow = function() {
	$.post(CONTEXT_PATH+"taskSubmitResult/changeTaskSubmitStatus?assignId="+ data.data.assignId, function(data) {
		if(data.status=="success"){
			alert("更改成功！");
			window.location.reload();
		}else{
			alert(data.message);
		}
	}); 
}

var downloadAll = function(){
	$("#download-url").attr("href",CONTEXT_PATH+"taskSubmitResult/downloadAll?assignId="+ data.data.assignId);
	$("#ensure-to-download-all-layer").modal("show");
}

var searchSubmit=function(){
	var assignId=data.data.assignId;
	var submitStatus =$("#submitStatus  option:selected").val();
	var json={
			assignId:assignId,
			status:submitStatus
	};
	if(submitStatus=="ALL"){
		delete json.status;
	} else if(submitStatus=="UNCOMMITTED"){
		json.status = "UNCOMMITTED";
	} else if(submitStatus=="COMMITTED"){
		json.status = "COMMITTED";
	} else if(submitStatus=="HAVEREAD"){
		json.status = "HAVEREAD";
	}
	ajaxSubmitList(JSON.stringify(json));
}

var ajaxSubmitList = function(json){
	$.get(CONTEXT_PATH+"taskSubmitResult/ajaxMtlistData", {
		data : json
	}, function(data) {
		if(data.status=="success"){
			initList(data.data);
		}else{
			alert("wrong");
		}
	}); 
}

var ifNoAttach = function(a){
	if(a == "{\"files\":[]}" || a == null || a == ""){
		return true;
	}
	return false;
}

var initList = function(data){
	var submitList=$("#submitList");
	submitList.empty();
	var list=data.list;
	if(list.length<=0){
		var s="<tr><td colspan=\"6\"><li>无记录</li></td></tr>";
		submitList.append(s);
	}else {
		for(var i=0;i<list.length;i++){
			var item=list[i];
			var s="";
			if(item.status=="UNCOMMITTED"){
				s+="<tr onclick=\"wrong()\">";
				s+="<td title=\""+item.ucode+"\">"+item.ucode+"</td>"
				s+="<td title=\""+item.assignedName+"\">"+item.assignedName+"</td>";
				s+="<td>---</td>";
				s+="<td title=\""+item.reviewName+"\">"+item.reviewName+"</td>";
				s+="<td>---</td>";
				s+="<td title=\"未提交\">未提交</td>";
			}else if(item.status=="COMMITTED"){
				if(ifNoAttach(item.resultAttachmentBytes)){
					s+="<tr bgcolor=\"#F2CECE\" onclick=\"initSubmitDetail("+item.id+")\">";
				}else{
					s+="<tr onclick=\"initSubmitDetail("+item.id+")\">";
				}				
				s+="<td title=\""+item.ucode+"\">"+item.ucode+"</td>"
				s+="<td title=\""+item.assignedName+"\">"+item.assignedName+"</td>";
				s+="<td title=\""+item.uploadTime+"\">"+item.uploadTime+"</td>";
				s+="<td title=\""+item.reviewName+"\">"+item.reviewName+"</td>";
				s+="<td>---</td>";
				s+="<td title=\"已提交\">已提交</td>";
			}else{
				if(ifNoAttach(item.resultAttachmentBytes)){
					s+="<tr bgcolor=\"#F2CECE\" onclick=\"initSubmitDetail("+item.id+")\">";
				}else{
					s+="<tr onclick=\"initSubmitDetail("+item.id+")\">";
				}
				
				s+="<td title=\""+item.ucode+"\">"+item.ucode+"</td>"
				s+="<td title=\""+item.assignedName+"\">"+item.assignedName+"</td>";
				s+="<td title=\""+item.uploadTime+"\">"+item.uploadTime+"</td>";
				s+="<td title=\""+item.reviewName+"\">"+item.reviewName+"</td>";
				if(item.isShare=="YES"){
					s+="<td title=\"已共享\">已共享</td>";
				}else{
					s+="<td title=\"未共享\">未共享</td>";
				}
				s+="<td title=\"已批阅-成绩:"+item.score+"\">已批阅--"+item.score+"</td>";
			}
			s+="</tr>"
			submitList.append(s);
		}
	}
}
var initSubmitDetail = function(id) {
	window.location.href = CONTEXT_PATH + "taskSubmitResult/detail?id=" + id;
}
var wrong = function() {
	alert("该学生还未提交任务！若想直接评分，可以点击“更改提交状态”按钮修改！所有任务！提交状态");
}
</script>
</html>